package com.sky.skyopsserver.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 凭据类型枚举
 * 
 * @author Administrator
 * @since 2025-01-17
 */
@Getter
@AllArgsConstructor
public enum CredentialTypeEnum {
    
    /**
     * 密码认证
     */
    PASSWORD(1, "密码认证"),
    
    /**
     * 密钥认证
     */
    SECRET_KEY(2, "密钥认证"),
    
    /**
     * 密码+密钥认证
     */
    PASSWORD_AND_KEY(3, "密码+密钥认证");
    
    /**
     * 类型值
     */
    private final Integer type;
    
    /**
     * 类型描述
     */
    private final String description;
    
    /**
     * 根据类型值获取枚举
     * 
     * @param type 类型值
     * @return 枚举
     */
    public static CredentialTypeEnum getByType(Integer type) {
        if (type == null) {
            return null;
        }
        for (CredentialTypeEnum credentialType : values()) {
            if (credentialType.getType().equals(type)) {
                return credentialType;
            }
        }
        return null;
    }
    
    /**
     * 验证类型是否有效
     * 
     * @param type 类型值
     * @return 是否有效
     */
    public static boolean isValid(Integer type) {
        return getByType(type) != null;
    }
}